<template>
    <div class="components-container">
        <div class="header-form" style="margin-bottom:0px;">
          <div class="layui-inline" >
            <label class="layui-form-label">业务编号</label>
            <div class="layui-inline">
            <el-input  v-model="selectData.RegbussnumLike" placeholder="请输入业务编号"></el-input>
            </div>
          </div>
          <el-button type="primary" @click="getData" :loading="this.$store.state.isloading">搜索</el-button>
          <el-button  @click="btnRepeat" >重置</el-button>
        </div>
        <div style="height:56px">
            <ul class="toolList">
                <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
                  <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
                </li>
            </ul>
        </div>
        <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
       <cost-add ref="costAdd" @refreshData="getData"></cost-add>
    </div>
</template>
<script>
import sweetModal from "@/components/sweetModal";
import dataTable from "@/components/Table/DataTable";
import costAdd from "./costAdd";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import { ORDER } from "@/const/orderConst.js";

const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";


export default {
  name: "cost",
  mixins: [manage],
  data() {
    return {
      selectDataExtend: {
      },
      //费用信息
      cotData: {},
    };
  },
  methods: {
    //获取表头
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetCostColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    //获取费用信息
    getData() {
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: this.selectData
      };
      apiBase.DoService(data, apiBase.getApiAdress().Cost.Query, res => {
        this.dataList = res.data.content.OutData;
        this.pageOrder.totalNum = res.data.content.RecordCount;
      });
    },
                //删除派车记录
    deleteCotInfo(cotid) {
      this.$confirm("此操作将永久删除该费用信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
        }).then(callback => 
         {
           var data = {
           COTID: cotid
          };
          apiBase.DoService(data, apiBase.getApiAdress().Cost.Delete, res => {
          this.getData();
            });
          });
    },
    //功能操作
    operate(order) {
      if(order==DELETE)
      {
        this.deleteCotInfo(this.currentRow.COTID);
        return;
      }
      this.order = order;
      this.openWindow(order,this.currentRow);
    },
    //打开子页面
    openWindow(order,id) {
     if(order==ADD)
     {
        this.$refs.costAdd.open(ORDER.ADD,null);
        return;
     }
     else 
     {  let pageOrder;
        if(order==MODIFY)
         pageOrder=ORDER.MODIFY;
        else if(order==INFO)
         pageOrder=ORDER.INFO;
        this.$refs.costAdd.open(pageOrder, this.currentRow.COTID);
     }
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {};
      this.initSeachdata();
      this.getData();
    },
    //按钮显隐
    btnShow(btn) {
      return true;
    },
    //测试打印
    testPrint() {
      console.log(this.$store.state.btnListCommon);
    },
    initSeachdata() {

    }
  },
  components: {
    sweetModal,
    dataTable,
    costAdd
  },
  activated() {
    this.getData();
  },
  mounted() {
    this.initSeachdata();
  },
  created() {
    this.initSeachdata();
    this.getColumns();
  },
};
</script>